# -*- coding:utf-8 -*-
import httplib, urllib, json
 
headers = {"Content-Type":"application/x-www-form-urlencoded",   
                   "Connection":"Keep-Alive","Referer":"http://127.0.0.1/"};   
conn = httplib.HTTPConnection("127.0.0.1", 8080);   
baseurl = '/discuss'

get_item = {}
#get_item['field'] = 'ding_count'
get_item['pageno'] = 0
get_item['type'] = 'list'
params = ''
for k,v in get_item.items():
    params += '&%s=%s' % (k, v)
myurl=baseurl + '?' + params[1:]
print params

conn.request(method="GET", url=myurl, body=params, headers=headers);
response = conn.getresponse(); 
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

get_item = {}
#get_item['field'] = 'ding_count'
get_item['discuss_id'] = 1
get_item['type'] = 'discuss'
params = ''
for k,v in get_item.items():
    params += '&%s=%s' % (k, v)
myurl=baseurl + '?' + params[1:]
print params

conn.request(method="GET", url=myurl, body=params, headers=headers);
response = conn.getresponse(); 
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

get_item = {}
get_item['discuss_id'] = 1
get_item['pageno'] = 1
get_item['type'] = 'comment'
params = ''
for k,v in get_item.items():
    params += '&%s=%s' % (k, v)
myurl=baseurl + '?' + params[1:]
print params

conn.request(method="GET", url=myurl, body=params, headers=headers);
response = conn.getresponse(); 
print response.status
print json.dumps(json.loads(response.read()), indent = 4)

conn.close();
